package DataReading;


// This class acts like an Array List, it keeps a Array of vessels as a list and extends the array as needed
// Keeps only what its needed. NOT COMPLETE YET, missing some features of a proper Array List to implement.
public class VesselList {
	
	// Variables of Class
	private Vessel[] list;
	private int pointer;
		
	// Default Constructor
	public VesselList() {
		list = new Vessel[10];
		pointer = 0;
	}
	
	// Parameterized Constructor
	public VesselList(int num) {
		list = new Vessel[num];
		pointer = 0;
	}
	
	// public void setList(Vessel[] li) { this.list = li; } - Not sure if mutator needed
	// Accessors for Class
	public int getPointer() { return pointer; }
	public Vessel[] getList() { return list; }
	
	// Get a Specific vessel at index - Not sure if it will be used
	public Vessel getVesselAtIndex(int index) {
		return list[index];
	}
	
	// Set a vessal at index - Not sure if it will be used
	public void setVesselAtIndex(Vessel v, int index) {
		list[index] = v;
	}
	
	// Adds a Vessel at the end of the list
	public void add(Vessel v) {
		if (list.length == pointer) { // Expand List if full
			expandValues();
		}
		list[pointer] = v;
		pointer++; 
	}
	
	public Vessel remove(int index) {
		Vessel temp = list[index];
		for (int i = index; i < pointer; i++) {
			list[i] = list[i+1]; // Pushes values back to fill the empty space
		}
		list[pointer] = null;
		pointer--;
		return temp; // Returns removed Node
	}
	
	// Expands the Array Size by doubling it - NEED TO WORK ON MAXIMUM 100
	public void expandValues() {
		Vessel temp[] = new Vessel[list.length*2];
		for (int i = 0; i < list.length; i++) {
			temp[i] = list[i]; 
		}
		list = temp;
		temp = null;
	}
	
	// Need to implement to trimList to size
	public void trimList() {
		Vessel temp[] = new Vessel[pointer+1];
		for (int i = 0; i < pointer+1; i++) {
			temp[i] = list[i]; 
		}
		list = temp;
		temp = null;
	}
	
	public String toString() {
		for (int i = 0; i < pointer; i++) {
			System.out.println(list[i].getID());
		}
		return "";
	}	
}
